import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';

export default {
  name: 'login',
  components: {},
  data () {
    return {
      siteId: '',
      studentId: '',
      openId: '',
      userName: '',
      userPass: '',
      idCardNeeds: false,
      placeholderText: '请输入学员姓名'
    }
  },
  mounted () {
    var _this = this
    _this.openId = window.sessionStorage.getItem('openId')
    //console.log('openid', _this.openId)
    _this.siteId = window.sessionStorage.getItem('siteId')
    //alert(_this.siteId + '****' + _this.openId)
    //console.log(_this.siteId)
    //console.log(CONSTANT.SETTING)

    // http.post(CONSTANT.LOGIN, {
    //   siteId: _this.siteId,
    //   userName: _this.userName,
    //   userPass: _this.userPass
    // }, (res) => {
    //   console.log(res)
    // })
  },
  methods: {
    goHello () {
      //else if (!idcard.test(_this.userName) && _this.idCardNeeds == true) {
      //  alert('请输入正确的身份证号码！')
      // }
      var _this = this
      var tel = /^[1][3,4,5,7,8][0-9]{9}$/
      var idcard = /^(\d{18}|\d{17}(x|X))$/
      if (_this.userPass == '') {
        alert('请输入手机号码！')
      }/* else if (!tel.test(_this.userPass)) {
        alert('请输入正确的手机号码！')
      } */else if (_this.userName == '') {
        alert(_this.placeholderText)
      }  else {
        http.post(CONSTANT.LOGIN, {
          username: _this.userName,
          password: _this.userPass,
          orgId: _this.siteId,
          loginKind: 'student',
          openId: ''
        }, (res) => {
          console.log(res)
        if (res.code != 0) {
          alert(res.msg)
        } else {
          let data = res.data
          _this.studentId = data.humanId
          window.sessionStorage.setItem('studentId', data.humanId)
          window.sessionStorage.setItem('studentName', data.studName)
          window.sessionStorage.setItem('userType', 0)
          this.$router.push({path: '/Hello'})
        }
      })
      }
    },
    goBack () {
      //this.$router.push({path: '/tabbar'})
      history.go(-1)
    }
  }
}
